﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Simulation.LogicalGate
{
    /// <summary>
    /// This class represents an abstract one input channel gate control.
    /// </summary>
    [Serializable]
    public class OneInputGateModule : AbstractInputGateModule
    {
        /// <summary>
        /// This field holds the specified gate function.
        /// </summary>
        private OneInputGate inputgate;

        /// <summary>
        /// This function pointer fetches the input information for the input channel. 
        /// </summary>
        private ByteGrabber byteGrabberInput;

        /// <summary>
        /// Initializes a new instance of the <see cref="OneInputGateModule"/> class.
        /// </summary>
        /// <param name="inputgate">The specified gate function.</param>
        /// <param name="byteGrabberInput">The function pointer, which fetches the input information for the input channel.</param>
        public OneInputGateModule(OneInputGate inputgate, ByteGrabber byteGrabberInput)
        {
            this.inputgate = inputgate;
            this.byteGrabberInput = byteGrabberInput;
        }

        /// <summary>
        /// Gets or sets the specified gate function.
        /// </summary>
        /// <value>The specified gate function.</value>
        public OneInputGate Inputgate
        {
            get { return inputgate; }
            set { inputgate = value; }
        }

        /// <summary>
        /// Gets or sets the function pointer fetches the input information for the input channel.
        /// </summary>
        /// <value>The function pointer fetches the input information for the input channel.</value>
        public ByteGrabber ByteGrabberInput
        {
            get { return byteGrabberInput; }
            set { byteGrabberInput = value; }
        }

        /// <summary>
        /// Gets the logical result, which is defined by the gate and the specified input values.
        /// </summary>
        /// <returns>The result of the logical gate.</returns>
        public override Byte GetResult()
        {
            this.inputgate.A = this.byteGrabberInput();

            return this.inputgate.GetResult();
        }
    }
}